package com.aidex.admin.controller.system;

import com.aidex.common.annotation.Log;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.query.QueryGenerator;
import com.aidex.common.utils.poi.ExcelUtil;
import com.aidex.system.domain.SysNoticeUserRead;
import com.aidex.system.service.SysNoticeUserReadService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * 通知公告用户阅读
 */
@RestController
@RequestMapping("/system/sysNoticeUserRead")
public class SysNoticeUserReadController extends BaseController<SysNoticeUserReadService> {

    /**
     * 查询通知公告用户阅读列表
     */
    @GetMapping("/list")
    public R page(SysNoticeUserRead entity,
                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                  HttpServletRequest req) {
        QueryWrapper<SysNoticeUserRead> queryWrapper = QueryGenerator.initQueryWrapper(entity, req.getParameterMap());
        Page<SysNoticeUserRead> page = new Page<>(pageNo, pageSize);
        IPage<SysNoticeUserRead> pageList = service.selectPage(page, queryWrapper);
        return R.data(pageList);
    }

    /**
     * 获取通知公告用户阅读详细信息
     */
    @GetMapping(value = "/{id}")
    public R detail(@PathVariable("id") String id) {
        return R.data(service.selectById(id));
    }

    /**
     * 新增通知公告用户阅读
     */
    @Log(title = "通知公告用户阅读", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated SysNoticeUserRead entity) {
        return R.status(service.insert(entity));
    }

    /**
     * 修改通知公告用户阅读
     */
    @Log(title = "通知公告用户阅读", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated SysNoticeUserRead entity) {
        return R.status(service.updateById(entity));

    }

    /**
     * 删除通知公告用户阅读
     */
    @Log(title = "通知公告用户阅读", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(service.deleteBatchIds(Arrays.asList(ids)));
    }


    /**
     * 导出通知公告用户阅读列表
     */
    @Log(title = "通知公告用户阅读", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(SysNoticeUserRead entity, HttpServletRequest req) {
        QueryWrapper<SysNoticeUserRead> queryWrapper = QueryGenerator.initQueryWrapper(entity, req.getParameterMap());
        List<SysNoticeUserRead> list = service.selectList(queryWrapper);
        ExcelUtil<SysNoticeUserRead> util = new ExcelUtil<>(SysNoticeUserRead.class);
        return util.exportExcel(list, "sysNoticeUserRead");
    }

}
